﻿
using DevelopAssistant.Service;
using ICSharpCode.WinFormsUI.Docking;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace DevelopAssistant.Core.Contents
{
    public partial class HomeContent : DockContent
    {
        System.Windows.Forms.Timer ScheduleTimer = null;

        public HomeContent()
        {
            InitializeComponent();
            InitializeControls();
        }

        private void HomeContent_Load(object sender, EventArgs e)
        {
            this.nScrollingText1.Text = "欢迎使用凌云开发助手，自2016年4月发布正式1.0版以来经历了4个重大版本的升级，详细见开源地址：https://gitee.com/sqlorm/DevelopAssistant。BY 凌云工作室 QQ 270885204";
            //this.nScrollingText1.Text += this.nScrollingText1.Text;
            this.nScrollingText1.ScrollText = this.nScrollingText1.Text;
            this.nScrollingText1.StopScrollOnMouseOver = true;
            this.ScrollingTextBox.Visible = false;

            System.Threading.Tasks.Task.Run(() => {
                System.Threading.Thread.Sleep(2000);
                this.ScrollingTextBox.Invoke(new MethodInvoker(delegate()
                {
                    this.ScrollingTextBox.Visible = true;
                    this.nScrollingText1.Visible = true;                
                }));            
            });

            List<TodoManager.TodoDTO> todoList = (List<TodoManager.TodoDTO>)AppSettings.ScheduleTasks;
            DoScheduleTasks(todoList);
        }

        private void InitializeControls()
        {
            this.nPanel1.BorderStyle = ICSharpCode.WinFormsUI.Controls.NBorderStyle.None;
        }

        private void DoScheduleTasks(List<TodoManager.TodoDTO> todoList)
        {
            if (todoList != null)
            {
                label1.Text = "已启用提醒";
                ScheduleTimer = new Timer(this.Container);
                ScheduleTimer.Interval = 2 * 1000 * 60; //2分钟刷新一次
                ScheduleTimer.Tick += ScheduleTimer_Tick;
            }
            else
            {
                label1.Text = "";
            }
        }

        private void ScheduleTimer_Tick(object sender, EventArgs e)
        {
            
        }

        private void nScrollingText1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("explorer.exe", "https://gitee.com/sqlorm/DevelopAssistant");
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.nScrollingText1.Visible = false;
            this.ScrollingTextBox.Controls.Remove(nScrollingText1);
            this.nScrollingText1.Dispose();
            this.Controls.Remove(ScrollingTextBox);
        }
    }
}
